package interfaceExercises.no1;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		PaymentProcessor paymentProcessor;
		Scanner scanner=new Scanner(System.in);
		while (true){
			try {
				System.out.println("请选择支付方法");
				System.out.println("1.支付宝");
				System.out.println("2.信用卡");
				System.out.println("0.退出");
				switch (scanner.nextInt()){
					case 1:
						paymentProcessor=new AliPayProcessor();
						break;
					case 2:
						paymentProcessor=new CreditCardPayProcessor();
						break;
					case 0:
						return;
					default:
						System.out.println("输入数字无效");
						continue;
				}
			}
			catch (InputMismatchException inputMismatchException){
				System.out.println("输入数字无效");
				continue;
			}
			paymentProcessor.payOrder();
		}
	}
}
interface PaymentProcessor{
	void payOrder();
}
class AliPayProcessor implements PaymentProcessor{
	@Override
	public void payOrder() {
		while (true){
			try {
				Scanner scanner = new Scanner(System.in);
				System.out.println("请输入金额");
				scanner.nextDouble();
				break;
			}
			catch (InputMismatchException inputMismatchException){
				System.out.println("输入数字无效");
			}
		}
	}
}
class CreditCardPayProcessor implements PaymentProcessor{
	@Override
	public void payOrder() {
		while (true){
			try {
				Scanner scanner = new Scanner(System.in);
				System.out.println("请输入金额");
				scanner.nextDouble();
				break;
			}
			catch (InputMismatchException inputMismatchException){
				System.out.println("输入数字无效");
			}
		}
	}
}